home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJTST200.ZIP / tests / libc / go32 / fpu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-06  |  507 b   |  34 lines

  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include <float.h>
  4.  
  5. void
  6. sf(int x)
  7. {
  8.   printf("FPU exception trapped!\n");
  9.   exit(1);
  10. }
  11.  
  12. float x = 0.0;
  13.  
  14. int
  15. main(void)
  16. {
  17.   double y;
  18.  
  19.   y = 3.2 + x;
  20.   printf("before the trap, y=%g\n", y);
  21.  
  22.   _control87(0, 0x3f); /* enable exceptions */
  23.   if (signal(SIGFPE, sf) == SIG_ERR)
  24.     printf("cannot set signal handler\n");
  25.  
  26.   raise(SIGFPE);
  27.   printf("after the raise\n");
  28.  
  29.   y = 1.0/x;
  30.   printf("after the trap, y=%g\n", y);
  31.  
  32.   return 0;
  33. }
  34.